
import React, { Component } from 'react';
import { BrowserRouter, Route, Link, Redirect, Switch,HashRouter } from "react-router-dom";
import { Row } from "./Layout/Row";
import { Col } from "./Layout/Col";
import { Button } from 'antd';

class Login extends Component {
    constructor(props) {
        super(props);
        this.state = { Login: false, To: null };
    }
    Login(e) {
        e.currentTarget.id == "Row" ? this.setState({ Login: true, To: "Row" }) : this.setState({ Login: true, To: "Col" });
    }
    render() {
        return (
            <BrowserRouter>
                <div>
                    <Route exact path="/" render={() =>
                        (this.state.Login ? <Redirect push to={`/Layout/${this.state.To}`} /> :
                            <div>
                                {/* <Link to="/Layout/Row">LingToRow</Link> */}
                                <h1 style={{ color: "red" }}>子路由必须带上上级路由的路径</h1> <br/>
                                <Button id="Row" onClick={this.Login.bind(this)}>登录Row</Button><br />
                                <Button id="Col" onClick={this.Login.bind(this)}>登录Col</Button>
                            </div>
                        )} />
                    <Switch>
                       
                        <Route path="/Layout/Col" component={Col} />
                        <Route path="/Layout/Row" component={Row} />
                    </Switch>
                </div>
            </BrowserRouter>
        );
    }
}
export { Login }
